package com.shanzhu.beadhouse.controller;


import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.shanzhu.beadhouse.common.constant.Constant;
import com.shanzhu.beadhouse.entity.base.Result;
import com.shanzhu.beadhouse.entity.po.ServiceLog;
import com.shanzhu.beadhouse.entity.query.AddLogQuery;
import com.shanzhu.beadhouse.entity.query.DeleteServiceLogQuery;
import com.shanzhu.beadhouse.entity.query.PageServiceLogQuery;
import com.shanzhu.beadhouse.service.IServiceLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "护理服务记录")
@RestController
@RequestMapping("/serviceLog")
@PreAuthorize("@AuthorityAssert.hasAuthority('/serve/log') or @AuthorityAssert.hasAuthority('/health/serveLogForNurse')")
public class ServeLogController {
    /**
     * 用于记录的获取,操作包括新增记录删除记录,在已知用户的记录中分页查找记录,根据服务类别分类查找记录
     */
    @Resource
    private IServiceLogService serviceLogService;


    @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX")
    @GetMapping("/addLog")
    @ApiOperation(value = "新增护理记录", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result addServiceLog(@ApiParam(value = "新增护理服务记录请求实体", required = true) AddLogQuery query,
                                @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token){


        return serviceLogService.addServiceLog(query);
    }



    @GetMapping("/pageServiceLog")
    @ApiOperation(value = "分页获取护理记录", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result pageServiceLog(@ApiParam(value = "分页获取护理服务记录请求实体", required = true) PageServiceLogQuery pageServiceLogQuery,
                                 @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token){
        return serviceLogService.pageServiceLog(pageServiceLogQuery);
    }

    @GetMapping("/deleteServiceLog")
    @ApiOperation(value = "删除护理记录", notes = Constant.DEVELOPER+Constant.EMPEROR_WEN)
    public Result deleteServiceLog(@ApiParam(value = "删除护理服务记录请求实体", required = true) DeleteServiceLogQuery query,
                                @ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token){
        System.out.println(JSONUtil.toJsonStr(query));

        return serviceLogService.deleteServiceLog(query);
    }
}
